﻿using System.Windows;
using System.Collections.ObjectModel;
using System.Windows.Controls;
using StockholmsStad.Windows.UI.Infrastructure.Windows;
using StockholmsStad.Windows.UI.Modules.Ceremony.Models;

namespace StockholmsStad.Windows.UI.Modules.Ceremony.Controls
{
    /// <summary>
    /// Interaction logic for CeremonyNextDetailsControl.xaml
    /// </summary>
    public partial class CeremonyNextDetailsControl
    {
        public CeremonyNextDetailsControl()
        {
            InitializeComponent();
        }

        public ObservableCollection<CeremonyDetailsPresentationModel> Model
        {
            get { return DataContext as ObservableCollection<CeremonyDetailsPresentationModel>; }
            set { DataContext = value; }
        }

        private void btnSpecialNeeds_Click(object sender, RoutedEventArgs e)
        {
            var button = e.Source as Button;

            if (button != null)
            {
                var model = button.DataContext as CeremonyDetailsPresentationModel;

                if (model != null && model.SpecialNeeds != null)
                {
                    var info = new SpecialNeedsInfo();
                    foreach (var need in model.SpecialNeeds)
                    {
                        info.AddSpecialNeed(need.Name);
                    }

                    var modal = new GenericModalWindow {GenericContent = info};
                    modal.ShowDialog();
                }                
            }
        }

        private void btnNotes_Click(object sender, RoutedEventArgs e)
        {
            var button = e.Source as Button;
            if (button != null)
            {
                var ceremony = button.DataContext as CeremonyDetailsPresentationModel;

                if(ceremony != null)
                {
                    var ceremonyNotes = new CeremonyNotes { Note = ceremony.Note };

                    var modal = new GenericModalWindow {GenericContent = ceremonyNotes};
                    modal.ShowDialog();                    
                }
            }
        }

        private void btnCancelBooking_Click(object sender, RoutedEventArgs e)
        {
            var result = MessageBox.Show("Är du säker på att du vill avboka följande bokning? Bokningen kommer även att tas bort från denna lista. ", "Avbokning",
                                         MessageBoxButton.OKCancel, MessageBoxImage.Warning);

            var button = e.Source as Button;
            if (button != null)
            {
                var dataModel = button.DataContext as CeremonyDetailsPresentationModel;

                if (dataModel != null)
                {
                    dataModel.ShouldCancel = result == MessageBoxResult.OK;
                }
            }
        }

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            var button = e.Source as Button;

            if (button != null)
            {
                var ceremony = button.DataContext as CeremonyDetailsPresentationModel;

                // Öppna printdialog

                var printSelector = new PrintSelector { Model = ceremony };
                var modalWindow = new GenericModalWindow { GenericContent = printSelector };
                modalWindow.ShowDialog();
            }
        }
    }
}
